//
//  CustomNavViewController.m
//  TLS
//
//  Created by 屠淋 on 15/8/8.
//  Copyright (c) 2015年 tulin. All rights reserved.
//

#import "CustomNavViewController.h"
#import "UINavigationBar+CustomImage.h"

@interface CustomNavViewController ()


@end

@implementation CustomNavViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

// 第一次使用这个类调用
+ (void)initialize
{
    // 设置导航栏主题
    [self setupNavBarTheme];
    // 设置导航栏item主题
    [self setupBarButtonItemTheme];
}

// 设置导航栏主题
+ (void)setupNavBarTheme
{
    // 取出 appearance对象
    UINavigationBar *navBar = [UINavigationBar appearance];

    //去掉navigation 的黑线
    
    [navBar setBackgroundImage:[[UIImage alloc] imageWithColor:[UIColor whiteColor]] forBarMetrics:UIBarMetricsDefault];
//    [navBar setBackIndicatorTransitionMaskImage:[[UIImage alloc] imageWithColor:[UIColor whiteColor]]];
    [navBar setShadowImage:[[UIImage alloc] imageWithColor:UIColorFromRGB(0xc9c9c9)]];//设置底部线的颜色
    
//    UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 43, SCREEN_WIDTH, 1)];
//    lineView.backgroundColor = UIColorFromRGB(0xa0a0a0);
//    [navBar addSubview:lineView];
//    [navBar sendSubviewToBack:lineView];
    // 设置背景
    
    [navBar setBarTintColor:[UIColor whiteColor]];
    
    // 设置标题属性
//    
//    if (!IsIos8Later) {
//        [navBar setTranslucent:NO];
//    }
    
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = ThemeColor;
    textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:17];
    [navBar setTitleTextAttributes:textAttrs];
    
    if (ios7) {
        navBar.backgroundColor = [UIColor whiteColor];
        navBar.barTintColor = [UIColor whiteColor];//背景色
        navBar.tintColor = [UIColor whiteColor];//字体颜色
    }else{
        UIImage *image = [UIImage new];
        image = [[UIImage alloc]init];
        [navBar setCustomBackgroundImage:image];
        navBar.clipsToBounds = YES;
        
//        if([navBar respondsToSelector:@selector(setShadowImage:)])
//            [navBar setShadowImage:image];
    }
}

// 设置导航栏item主题
+ (void)setupBarButtonItemTheme
{
    UIBarButtonItem *item = [UIBarButtonItem appearance];
    // 设置背景
    if (!ios7) {
        [item setBackgroundImage:[UIImage imageWithName:@"navigationbar_button_background"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
        
        [item setBackgroundImage:[UIImage imageWithName:@"navigationbar_button_background_pushed"] forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
        [item setBackgroundImage:[UIImage imageWithName:@"navigationbar_button_background_disable"] forState:UIControlStateDisabled barMetrics:UIBarMetricsDefault];
    }
    
    // 设置文字属性
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = ios7 ? [UIColor orangeColor] : [UIColor grayColor];
    textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:ios7 ? 15 : 12];
    [item setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:textAttrs forState:UIControlStateHighlighted];
    NSMutableDictionary *disableTextAttrs = [NSMutableDictionary dictionary];
    disableTextAttrs[NSForegroundColorAttributeName] = [UIColor lightGrayColor];
    [item setTitleTextAttributes:disableTextAttrs forState:UIControlStateDisabled];
    
   

}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.viewControllers.count > 0) {
        viewController.hidesBottomBarWhenPushed = YES;
    }
    [super pushViewController:viewController animated:animated];
}



@end
